package com.bh.mapper;

import com.bh.pojo.entry.Menu;
import com.bh.pojo.entry.User;
import com.bh.pojo.vo.UserVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserMapper {

    //增
    @Insert("insert into user values(null,#{username},#{password},#{phone},#{sex},#{birthday}," +
            "#{photo},#{hobby},#{address},0)")
    Integer addUser(User user);
    //查
    @Select("select * from user where username=#{username} and password=#{password}")
    User loginUser(User user);

    List<UserVO> findAll(@Param("likename") String likename);

    @Select("select DISTINCT m.* from user u\n" +
            "inner join user_role ur on u.id=ur.uid\n" +
            "inner join role r on ur.rid=r.rid\n" +
            "inner join role_menu rm on r.rid = rm.rid\n" +
            "inner join menu m on rm.mid = m.mid where u.id=#{value}")
    List<Menu> findMenuByUserId(Integer id);

}

